/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */

import { Users } from "../domains/index.js";
import { scoreSymbol, type LLMIntegrationTest, type ScorableVerboseTree } from "../utils.js";

const expected: ScorableVerboseTree = {
	type: "com.microsoft.fluid.tree-agent.users.Users",
	[scoreSymbol]: (actual): number => {
		if (typeof actual !== "object" || actual === null || Array.isArray(actual.fields)) {
			return 0;
		}

		const userId = "alvillarreal";
		const user = actual.fields[userId];

		// All-or-nothing scoring; either the user is valid and its display name is correct, or not.
		if (
			typeof user !== "object" ||
			user === null ||
			Array.isArray(user.fields) ||
			user.type !== "com.microsoft.fluid.tree-agent.users.User"
		) {
			return 0;
		}
		if (
			typeof user.fields.displayName === "string" &&
			user.fields.displayName.toLowerCase() === "alvillarreal"
		) {
			return 1;
		}

		return 0;
	},
};

/**
 * Test that tries to get the LLM to set a user's display name using the method exposed from the schema class.
 * The edit function generated by the LLM should basically just be a call to the `setDisplayName` method
 * on the user object.
 */
export const methodUseTest = {
	name: "Method use",
	schema: Users,
	initialTree: () => ({
		alvillarreal: {
			firstName: "alejandro",
			lastName: "villarreal",
			created: "2025-01-01T00:00:00.000Z",
			email: "alejandrovi@microsoft.com",
		},
	}),
	prompt: "Update the user's display name.",
	expected,
} as const satisfies LLMIntegrationTest<typeof Users>;
